<template>
    <div class="Nav"  :class="[onoff ? 'on' : '']">
        <div class="Nav_con">
            <img src="https://erabbit-test.itheima.net/img/logo.0940ebb5.png" alt="">
            <ul class="Nav_list">
                <li @click="gotoHome">首页</li>
                <li class="Nav_li" v-for="item in childList" :key="item.id" @click="toClass(item.id,item.name)">
                    {{ item.name }}
                    <div class="Nav_list2">
                        <ul class="Nav_list3">
                            <li class="Nav_li2" v-for="i in item.children" :key="i.id">
                                <img v-lazy=i.picture alt="">
                                <p>{{i.name}}</p>
                            </li>
                        </ul>
                    </div>
                </li>
            </ul>
            <div class="ri" v-if="!onoff">
                <div class="search">
                    <van-icon class="icon" name="search" />
                    <input class="inp" type="text" placeholder="搜一搜">
                </div>
                <div class="shop" >
                    <van-goods-action-icon class="car" icon="cart-o"  :badge=goodsList.length @click="gotoShopping"/>
                    <div class="car_i">
                        <div class="car_list">
                            <div class="car_li" v-for="item in goodsList" :key="item.id">
                                <img class="im" :src=item.picture alt="">
                                <div class="con">
                                    <p class="p1">{{ item.name }}</p>
                                    <p class="p2">{{item.attrsText}}</p>
                                </div>
                                <div class="ri">
                                    <p class="p1">￥{{item.price}}</p>
                                    <p class="p2">X{{item.count}}</p>
                                </div>
                            </div>
                        </div>
                        <div class="bot">
                            <div class="le">
                                <p class="p1">共{{ goodsList.length }}件商品</p>
                                <p class="p2">￥{{ theSum }}</p>
                            </div>
                            <button class="ri" @click="gotoShopping">去购物车结算</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="right" v-if="onoff">
                <p>品牌</p>
                <p>转题</p>
            </div>
          
        </div>
       
    </div>
</template>

<script>
export default {
    name:'NavigationBar',
    data(){
        return{
            childList:'',
            onoff:null,
            goodsList:[]

        }
    },
    mounted(){
       
        window.addEventListener("scroll",(e)=>{
            if(document.documentElement.scrollTop >= 100){
                this.onoff = true
            }else{
                this.onoff= false
            }
            
        })
        this.$.getHomeTwoMenu().then((res)=>{
            this.childList=res.data.result
            // this.bus.$emit('itemFn',{childList:this.childList})
        })
        this.$.getGoodsList().then((res)=>{
            this.goodsList=res.data.result
            console.log( this.goodsList);
        })
    },
    computed:{
        theSum(){
            let num =0;
            this.goodsList.forEach((item)=>{
                let num1 = item.price*1;
                let num2 = item.count;
                let num3 =num1*num2;
                num += num3;
                console.log(num3)
            })
            return num;
        }
    },
    methods:{
        gotoShopping(){
            this.$router.push({
                path:"/shoppingCar"
            })
        },
        gotoHome(){
            this.$router.push({
                path:"/Home",
            })
        },
        toClass(a,b){
            this.$router.push({
                name:"classiFication",
                query:{
                    id:a,
                    name:b
                }
            })
        }
    }
}
</script>
<style lang="less" scoped>
    @keyframes ss{
        0%{height: 0;}
        100%{height: 80px;}
    }
    .Nav{
        width: 100%;
        background: #fff;
        height: 136px;
        position: relative;
        // overflow: hidden;
        z-index: 9999999;
        &.on{
            position: fixed;
            top:0;
            left:0;
            z-index: 9999999999;
            height: 80px;
             animation: ss .3s linear 0s 1 alternate forwards ;
            // transition: opacity 3s;
        }
        &.on img{
            width: 200px;
            height: 80px;
        }
        &.on .Nav_list2{
            top:80px;
        }
    }
    .Nav_con{
        width: 1240px;
        margin: 0 auto;
        display: flex;
        align-items: center;
        position: relative;
        position: sticky;
        top: 50px;
        .ri{
            display: flex;
            margin: 0 0 0 20px;
            .search{
                width: 170px;
                height: 32px;
                position: relative;
                border-bottom: 1px solid #e7e7e7;
                line-height: 32px;
                display: flex;
                align-items: center;
                .icon{
                    font-size: 18px;
                    margin-left: 5px;
                }
                .inp{
                    border: none;
                    width: 140px;
                    padding-left: 5px;
                    color: #666;
                    font-size: 16px;
                }
            }
            .shop{
                width: 50px;
                display: flex;
                .car{
                    line-height: 32px;
                    text-align: center;
                    font-size: 22px;
                    font-weight: 400;
                }
               
            }
        }
       .right{
            display: flex;
            font-size: 16px;
            p{
                 margin-left: 30px;
                 color: #333;
            }
           
       }
        img{
            width: 200px;
            height: 122px;
        }
        .Nav_list{
            width: 820px;
            display: flex;
            justify-content: space-around;
            padding-left: 40px;
            box-sizing: border-box;
            list-style: none;
            font-size: 16px;
            color: #333;
            border-right: 1px solid #27ba9b;
           
            .Nav_li{
                height: 25px;
            }
           
        }
        .Nav_list .Nav_li:hover{
            color: #27ba9b;
            border-bottom: 1px solid #27ba9b;      
        }
        .Nav_list2{
        width: 1240px;
        height: 0px;
        background: #fff;
        position: absolute;
        left: 50%;
        margin-left: -620px;
        top:120px;
        z-index: 999999;
        .Nav_list3{
            display: flex;
            padding: 0 0 0 100px;
            box-sizing: border-box;
          
            // z-index: 99 !important;
            // display: none;

            .Nav_li2{
                display: flex;
                flex-direction: column;
                width: 130px;
                height: 120px;
                // border: 1px solid #000;
                align-items: center;
                
            }
           
            img{
                width: 100px;
                height: 80px;
            }
            p{
                font-size: 16px;
                margin-top: 5px;
            }
        }
    }
    .Nav_li .Nav_list2{
        transition: 1s;
        height: 0px;
        overflow: hidden;

    }   
    .Nav_li:hover .Nav_list2{
        height: 130px;
        box-shadow: 0px 0px 5px #888;
    } 
    .car_i{
        width: 400px;
        // height: 400px;
        height: 0;
        overflow: hidden;
        transition: .3s;
        background: #fff;
        box-shadow: 0px 0px 5px rgba(0,0,0,.1);
        position: absolute;
        right: 0;
        border-radius: 5px;
        top:100px;
        box-sizing: border-box;
        &::before{
            content: "";
            position: absolute;
            right: 14px;
            top: -10px;
            width: 20px;
            height: 20px;
            background: #fff;
            transform: scaleX(.6) rotate(45deg);
            box-shadow: -3px -3px 5px rgba(0,0,0,.1)
        }
        .bot{
            width: 100%;
            height: 70px;
            background: #f8f8f8;
            position: absolute;
            bottom: 0;
            left: 0;
            padding: 10px;
            box-sizing: border-box;
            display: flex;
            justify-content: space-between;
            .le{
                display: flex;
                flex-direction: column;
                justify-content: center;
                .p1{
                    color: #999;
                    font-size: 14px;
                }
                .p2{
                    color: #cf4444;
                    font-size: 18px;
                }
            }
            .ri{
                width: 180px;
                height: 50px;
                border: none;
                border: 1px solid #27ba9b;
                color: #27ba9b;
                background: #e6faf6;
                border-radius: 4px;
                display: inline-block;
                font-size: 16px;
                text-align: center;
                line-height: 50px;

            }
        }
        .car_list{
            width: 100%;
            height: 310px;
            padding: 0 10px;
            box-sizing: border-box;
            overflow-y:hidden;
            overflow-y:scroll;

            .car_li{
                width: 100%;
                // height: 80px;
                border-bottom: 1px solid #f5f5f5;
                padding: 10px 0;
                display: flex;
                &:last-child{
                    border-bottom: none;
                }
                .im{
                    width: 80px;
                    height: 80px;
                }
                .con{
                    display: flex;
                    flex-direction: column;
                    justify-content: center;
                    margin-left: 10px;
                    .p1{
                        font-size: 16px;
                        // margin-top: 10px;
                    }
                    .p2{
                        font-size: 16px;

                        color: #999;
                        padding-top: 5px;
                    }
                }
                .ri{
                    display: flex;
                    flex-direction: column;
                    justify-content: center;
                    margin-left: 10px;
                    .p1{
                        font-size: 16px;
                        color: #cf4444;
                    }
                    .p2{
                        color: #999;
                        margin-top: 5px;
                        font-size: 16px;
                    }
                }
            }
        }

    }
    .shop:hover .car_i{
        height: 400px;
        box-shadow: 0px 0px 5px rgba(0,0,0,.1);

    }
    
    }
</style>